package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.MesProduceWorkmanship;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.MesProduceWorkmanshipDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2022-03-30 15:32:05
 */
public class MesProduceWorkmanshipConverts {

    private static Logger LOG = LoggerFactory.getLogger(MesProduceWorkmanshipConverts.class);

    public static List<MesProduceWorkmanshipDTO> convert(List<MesProduceWorkmanship> mesProduceWorkmanshipList) {
        if (CollectionUtils.isEmpty(mesProduceWorkmanshipList)) {
            return Collections.EMPTY_LIST;
        }

        List<MesProduceWorkmanshipDTO> mesProduceWorkmanshipListResult = Lists.newArrayList();
        for (MesProduceWorkmanship mesProduceWorkmanship : mesProduceWorkmanshipList) {
            mesProduceWorkmanshipListResult.add(convert(mesProduceWorkmanship));
        }
        return mesProduceWorkmanshipListResult;
    }

    public static MesProduceWorkmanshipDTO convert(MesProduceWorkmanship mesProduceWorkmanship) {
        try {
            return BeanUtils.copy(mesProduceWorkmanship, MesProduceWorkmanshipDTO.class);
        } catch (Exception e) {
            LOG.error("MesProduceWorkmanship到MesProduceWorkmanshipDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesProduceWorkmanship到MesProduceWorkmanshipDTO转换失败", e);
        }
    }

    public static MesProduceWorkmanship convert(MesProduceWorkmanshipDTO mesProduceWorkmanshipDTO) {
        try {
            return BeanUtils.copy(mesProduceWorkmanshipDTO, MesProduceWorkmanship.class);
        } catch (Exception e) {
            LOG.error("MesProduceWorkmanshipDTO到MesProduceWorkmanship转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesProduceWorkmanshipDTO到MesProduceWorkmanship转换失败", e);
        }
    }
}